import request from '@/utils/request'

export function login (data) {
  return request({ url: 'authorizations', method: 'POST', data })
}

export function follow (id) {
  return request({ url: 'user/followings', method: 'POST', data: { target: id } })
}

export function unFollowed (id) {
  return request({ url: `user/followings/${id}`, method: 'DELETE' })
}

export function like (target) {
  return request({ url: 'article/likings', method: 'POST', data: { target } })
}

export function unLike (target) {
  return request.delete(`article/likings/${target}`)
}

export function dislike (target) {
  return request.post('article/dislikes', { target })
}

export function unDislike (target) {
  return request.delete(`article/dislikes/${target}`)
}

export function getCommentsApi (params) {
  return request({
    url: 'comments',
    params
  })
}

export function addCommentsApi (data) {
  return request.post('comments', data)
}

export function getUserProfileApi () {
  return request({
    url: 'user'
  })
}

/**
 * 获取个人中心用户编辑资料信息
 */
export function getUserProfile () {
  return request({ url: 'user/profile' })
}

export function editUserProfileApi ({ name, birthday, gender }) {
  return request.patch('user/profile', { name, birthday, gender })
}

export function editPhotoApi (data) {
  const fromdata = new FormData()
  fromdata.append('photo', data)
  return request.patch('user/photo', fromdata)
}
